<?php 

/**
* 
*/
class Category_model extends Model
{
	
	function __construct()
	{
		parent::__construct();
	}

	public function list_view () {

		$q = $this->db->prepare('Select Id,Name,Path,Img FROM categories');
		$q->execute();
		return $q->fetchAll(); 
	}

	public function edit_view($id){

		$q = $this->db->prepare('Select Id,Name,Path,Img FROM categories WHERE Id = :Id');

		$q->execute(array(
			':Id'	=> $id
		));

		return $q->fetch(); 
	}

	public function create($data) {
		
		$q = $this->db->prepare('INSERT INTO categories (Name,Path,Img)
											VALUES (:Name,:Path,:Img)');
		$q->execute(array(
			':Name'		=>	$data['Name'],
			':Path'		=>	$data['Path'],
			':Img'		=>	$data['Img']
		));		
	}
	public function edit_save ($data) {

		$q = $this->db->prepare('UPDATE categories SET Name = :Name,Path = :Path ,Img = :Img WHERE Id = :Id');
		$q->execute( array(
			':Name' 	=> $data['Name'], 
			':Path' 	=> $data['Path'], 
			':Img' 		=> $data['Img'], 
			':Id' 		=> $data['Id']
		));
	}

	public function delete ($id) {
		$q = $this->db->prepare('DELETE FROM categories WHERE Id = :Id');
		$q->execute(array(
			':Id'		=> $id 
		));
	}
}
?>